<?php 

include_once 'site_config.php';
include_once "ra_global.php";

function getToken($url){
	$ch = curl_init(); 
	curl_setopt($ch, CURLOPT_URL,$url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
	$row=curl_exec($ch); 
	return $row;
}

if(!$_GET['code']){
	$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=".urlencode(SiteUrl.'opnion.php')."&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
	echo "<script language=javascript>location.href='".$url."';</script>";
}

//获取code
$getcode=getToken("https://api.weixin.qq.com/sns/oauth2/access_token?appid=".APPID."&secret=".APPSECRET."&code=".$_GET['code']."&grant_type=authorization_code");


$user_obj=json_decode($getcode);

if($user_obj->openid){
	$user=$db->ig2_want('mae_user','openid="'.trim($user_obj->openid).'" and is_delete=0');
	if(!$user) tellgoto('','user.php');
}else{
	echo "<script language=javascript>location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=".urlencode(SiteUrl.'opnion.php')."&response_type=code&scope=snsapi_base&state=1#wechat_redirect';</script>";
} 

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,target-densitydpi=high-dpi,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<link href="images/m.css" rel="stylesheet" type="text/css" />
<script src="inc/jquery.min.js" type="text/javascript"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js" type="text/javascript"></script>
<title>喜力超凡大师</title>
</head>

<body>
<script language="javascript">


function onBridgeReady(){
	WeixinJSBridge.call('hideOptionMenu');
}

if (typeof WeixinJSBridge == "undefined"){
	if( document.addEventListener ){
		document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
	}else if (document.attachEvent){
	document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
	document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
	}
}else{
	onBridgeReady();
}
</script>
<div class="container" style="display:none">
	<div class="p9">
		<img class="p9bg bg" src="images/p9bg.jpg">
		<img class="txt" id="p9_1" src="images/p9_1.jpg">
        <script>
			document.getElementById("p9_1").addEventListener("touchstart", touchStartp9_1, false);
			document.getElementById("p9_1").addEventListener("touchend", touchEndp9_1, false);
			function touchStartp9_1(event){
				startX = event.touches[0].clientX;
				document.getElementById('p9_1').src='images/p9_1_h.jpg';	
			}
			function touchEndp9_1(event){
				endX = event.changedTouches[0].clientX;
				document.getElementById('p9_1').src='images/p9_1.jpg';
			}	
		</script>
		<textarea class="bt" id="p9text"></textarea>
		<img id="p9mb_1" src="images/p9mb_1.png">
		<img id="p9mb_2" src="images/p9mb_2.png">
		<img id="p9bt_1" class="p9bt" src="images/p2bar_1.jpg">
        <script>
			document.getElementById("p9bt_1").addEventListener("touchstart", touchStartp9bt_1, false);
			document.getElementById("p9bt_1").addEventListener("touchend", touchEndp9bt_1, false);
			function touchStartp9bt_1(event){
				startX = event.touches[0].clientX;
				document.getElementById('p9bt_1').src='images/p2bar_1_h.jpg';	
			}
			function touchEndp9bt_1(event){
				endX = event.changedTouches[0].clientX;
				document.getElementById('p9bt_1').src='images/p2bar_1.jpg';
			}	
		</script>
		<img id="p9bt_2" class="p9bt" src="images/p9bt.jpg">
        <script>
			document.getElementById("p9bt_2").addEventListener("touchstart", touchStartp9bt_2, false);
			document.getElementById("p9bt_2").addEventListener("touchend", touchEndp9bt_2, false);
			function touchStartp9bt_2(event){
				startX = event.touches[0].clientX;
				document.getElementById('p9bt_2').src='images/p9bt_h.jpg';	
			}
			function touchEndp9bt_2(event){
				endX = event.changedTouches[0].clientX;
				document.getElementById('p9bt_2').src='images/p9bt.jpg';
			}	
		</script>
	</div>	
</div>
<script type="text/javascript">
var x,y,p;
window.onload=function(){
	$('.container').show(); 
}
$(document).ready(function() {
	x=parseInt(window.innerWidth);
	y=parseInt(window.innerHeight);
	p=720/x;
	getWidth();
});

function trim(str){
	return str.replace(/(^\s*)|(\s*$)/g, "");
}

$('#p9bt_1').click(function(){
	wx.closeWindow()
	// $('#p9mb_1,#p9bt_1').fadeOut(500);
	// $('#p9text').val('');
});

$('#p9bt_2').click(function(){
	$('#p9mb_2,#p9bt_2').fadeOut(500);
});

$('#p9_1').click(function(){
	var content=trim($("#p9text").val());
	if(content==''){
		$('#p9mb_2,#p9bt_2').fadeIn(500);
	}else{
		var uid='<?php echo $user['id']?>';
		$.ajax({
			type:'GET',
			url:"ra_ajax.php?opnion=1&uid="+uid+"&content="+content,
			success: function(data){
				if(data == 'success'){
					$('#p9mb_1,#p9bt_1').fadeIn(500);
					//setTimeout("location.href='user.php'",1500)
				}else{
					alert('提交失败');
				}
			},
			error:function(){
				
			},
		});
	}
});

function getWidth(){
	$('.p9,.container,.bg,#p9mb_1,#p9mb_2').width(x);
	$('.p9,#p9mb_1,#p9mb_2').css({left:0,top:0});
	//p9
	$('#p9_1').width(530/p).height(77/p);
	$('#p9_1').css({left:(x-530/p)/2+'px',top:823/p+'px'});
	$('#p9text').css({left:(x-530/p)/2+'px',top:260/p+'px',width:530/p+'px',height:544/p+'px',fontSize:24/p+'px'});
	$('.p9bt').width(134/p).height(76/p);
	$('.p9bt').css({left:(x-134/p)/2+'px',top:625/p+'px'});
}
</script>
</body>
</html>